package com.zpf.service.impl;

import com.zpf.dao.UserDao;
import com.zpf.dao.impl.UserDaoImpl;
import com.zpf.pojo.User;
import com.zpf.service.UserService;

public class UserServiceImpl implements UserService {

    UserDao userDao = new UserDaoImpl();

    @Override
    public boolean checkUsername(String username) {
        //查询数据库是否存在此用户名
        //发起查询：根据用户名查询用户的个数
        long count = userDao.selectCountByUsername(username);
        return count > 0;
    }

    @Override
    public boolean register(String username, String password, String email, String gender) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setGender(gender);
        user.setEmail(email);
        //设置用户的状态为 激活
        user.setFlag(1);
        //激活码
//        user.setCode();
        int count = userDao.insert(user);
        return count == 1;
    }

    @Override
    public User login(String username, String password) {
        User user =   userDao.selectbyUsernameAndPassword(username,password);
        return user;

    }
}
